// =====================================================================================
// Copyright ?2006 SmartCodeGenerator created by Shahed Khan. 
/*
//Microsoft Shared Source Community License (MS-CL)
//Published: October 18, 2005
*/
// If you like this code then feel free to go ahead and use it.
// Your use of this software is entirely at your own risk.
// I make no claims or warrantees about the reliability or fitness of this code for any particular purpose.
// website www.smartcodegenerator.com, email shahed.khan@gmail.com
// =====================================================================================

namespace SmartCodeGen.Providers
{
    using System;
    using System.ComponentModel;

    /// <summary>
    /// Provides a base for all schema objects to derive from.
    /// </summary>
    [Serializable]
    public abstract class SchemaBase
    {
        /// <summary>
        /// The default constructor for this object.
        /// </summary>
        public SchemaBase()
        {
            this.name = string.Empty;
            this.description = string.Empty;
            this.extendedProperties = null;
            
        }

        /// <summary>
        /// Allows the object to be refreshed.
        /// </summary>
        public virtual void Refresh( )
        {
            this.extendedProperties = null;
            
        }


        /// <summary>
        /// Allows access to the DatabaseSchema object that contains this schema object.
        /// </summary>
        [Browsable(false)]
        public virtual DatabaseSchema Database
        {
            get
            {
                return this.database;
            }
        }

        /// <summary>
        /// The description of the object.
        /// </summary>
        //public virtual string Description
        //{
        //    get
        //    {
        //        throw new NotImplementedException();
        //    }
        //}

        /// <summary>
        /// Used to store any additional information about the schema object.
        /// </summary>
        
        public virtual ExtendedPropertyCollection ExtendedProperties
        {
            get
            {
                if ((this.extendedProperties == null) )
                {
                    //this.Database.c();
                    if (this.extendedProperties == null)
                    {
                        this.extendedProperties = new ExtendedPropertyCollection();
                        this.extendedProperties = DBSchema.GetExtendedProperties(this);
                    }
                    else
                    {
                        ExtendedPropertyCollection propertyArray1 = DBSchema.GetExtendedProperties(this);
                        for (int num1 = 0; num1 < propertyArray1.Count; num1++)
                        {
                            int num2 = this.extendedProperties.IndexOf(propertyArray1[num1].Name);
                            if (num2 >= 0)
                            {
                                this.extendedProperties[num2] = propertyArray1[num1];
                            }
                            else
                            {
                                this.extendedProperties.Add(propertyArray1[num1]);
                            }
                        }
                    }
                }
                return this.extendedProperties;
              
            }
        }

        /// <summary>
        /// The name of the object.
        /// </summary>
        public virtual string Name
        {
            get
            {
                return this.name;
            }
        }


        protected DatabaseSchema database;
        protected string description;
        protected ExtendedPropertyCollection extendedProperties;
        //protected bool gotExtendedProperties;
        protected string name;
        protected string connectionString;
        protected DBSchemaProvider databaseSchemaProvider;
        
        public string ConnectionString
        {
            get { return connectionString; }
            set { connectionString = value; }
        }

        public DBSchemaProvider DatabaseSchemaProvider
        {
            get { return databaseSchemaProvider; }
            set { databaseSchemaProvider = value; }
        }


    }
}

